﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EShop.BussinessObjects;
using EShop.Common;
using EShop.DataAccess;
using EShop.BusinessLogic;

public partial class EditProfile : BaseThemePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!CGlobalData.IsLoggedIn())
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                fillPage();
            }
        }
    }


    private void fillPage()
    {
        int contactID = CGlobalData.GetCurrentContactID();

        User user_Filter = new User();
        user_Filter.ID = ((int)cnstDatabase.DBOperationResult.ValueIsNotEffective);
        user_Filter.Contact = new Contact();
        user_Filter.Contact.ID = contactID;
        user_Filter.LoginID = ((int)cnstDatabase.DBOperationResult.ValueIsNotEffective).ToString();
        List<User> userList = CBLUser.Select(user_Filter);
        if (userList.Count > 0)
        {
            UserBonus userBonus_Filter = new UserBonus();
            userBonus_Filter.ID = ((int)cnstDatabase.DBOperationResult.ValueIsNotEffective);
            userBonus_Filter.Company = new Company();
            userBonus_Filter.Company.ID = CGlobalData.GetCurrentCompanyID();
            userBonus_Filter.User = new User();
            userBonus_Filter.User.ID = userList.First().ID;
            List<UserBonus> userBonusList = CDAUserBonus.Select(userBonus_Filter);

            if (userBonusList.Count > 0)
                lblBonusCount.InnerText = userBonusList.First().Cnt.ToString();
            else
                lblBonusCount.InnerText = "0";
        }
        

        Contact contact_Filter = new Contact();
        contact_Filter.ID = contactID;
        List<Contact> contacts=CDAContact.Select(contact_Filter);
        Signup1.Mode = "EditProfile";
        Signup1.FillUserControl(contacts[0]);
    }
}
